package router

import (
	"game_server/framework/task"
)

type HandlerFunc func(taskWrapper *task.TaskWrapper) *task.TaskWrapper

var _routerManager *RouterManager = nil

type RouterManager struct {
	routerPool map[int]HandlerFunc
}

func RouterManagerInstance() *RouterManager { return _routerManager }

func InitRouterManager() {
	routerManager := &RouterManager{routerPool: make(map[int]HandlerFunc)}
	_routerManager = routerManager
}

func (r *RouterManager) AddRouter(key int, handle HandlerFunc) {
	_, ok := r.routerPool[key]
	if !ok {
		r.routerPool[key] = handle
	}
}

func (r *RouterManager) RemoveRouter(key int) {
	_, ok := r.routerPool[key]
	if !ok {
		return
	}
	delete(r.routerPool, key)
}

func (r *RouterManager) QueryRouter(key int) HandlerFunc {
	value, ok := r.routerPool[key]
	if !ok {
		return nil
	}
	return value
}
